﻿<navigation:PageView x:Class="Corina.Cydee.Apphub.Views.Devices.DevicekindView"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:controls="clr-namespace:Corina.Controls.Silverlight;assembly=Corina.Controls.Silverlight"
                     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                     xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                     xmlns:localViewmodel="clr-namespace:Corina.Cydee.Apphub.Viewmodels"
                     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                     xmlns:navigation="clr-namespace:Corina.Cydee.Apphub.Base"
                     Title="设备分类"
                     d:DesignHeight="480"
                     d:DesignWidth="800"
                     mc:Ignorable="d">
    <navigation:PageView.DataContext>
        <localViewmodel:DevicekindViewmodel />
    </navigation:PageView.DataContext>
    <Grid x:Name="LayoutRoot">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition />
                </Grid.RowDefinitions>

                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="300" />
                        <ColumnDefinition />
                        <ColumnDefinition Width="auto" />
                    </Grid.ColumnDefinitions>
                    <TextBlock VerticalAlignment="Center"
                               Style="{StaticResource ControlLabelStyle}"
                               Text="关键字：" />
                    <TextBox Grid.Column="1" Text="{Binding Keywords, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

                    <Button Grid.Column="3"
                            Width="60"
                            Command="{Binding InsertCommand}"
                            Content="新增" />
                </Grid>

                <ListBox Grid.Row="1"
                         Margin="0,12,0,0"
                         ItemsSource="{Binding DisplayCollection}"
                         SelectedItem="{Binding SelectedDeviceKindItem,
                                                Mode=TwoWay}">
                    <ListBox.ItemContainerStyle>
                        <Style TargetType="ListBoxItem">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="ListBoxItem">
                                        <Grid>
                                            <VisualStateManager.VisualStateGroups>
                                                <VisualStateGroup x:Name="SelectionStates">
                                                    <!--
                                                        <VisualStateGroup.Transitions>
                                                        <VisualTransition GeneratedDuration="0:0:0.4" />
                                                        </VisualStateGroup.Transitions>
                                                    -->
                                                    <VisualState x:Name="SelectedUnfocused">
                                                        <Storyboard>
                                                            <DoubleAnimation Duration="0:0:0.4"
                                                                             Storyboard.TargetName="grid"
                                                                             Storyboard.TargetProperty="(UIElement.Opacity)"
                                                                             To="1"
                                                                             d:IsOptimized="True" />
                                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                                    <DiscreteObjectKeyFrame.Value>
                                                                        <Visibility>Visible</Visibility>
                                                                    </DiscreteObjectKeyFrame.Value>
                                                                </DiscreteObjectKeyFrame>
                                                            </ObjectAnimationUsingKeyFrames>
                                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="txtCount" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                                    <DiscreteObjectKeyFrame.Value>
                                                                        <Visibility>Visible</Visibility>
                                                                    </DiscreteObjectKeyFrame.Value>
                                                                </DiscreteObjectKeyFrame>
                                                            </ObjectAnimationUsingKeyFrames>
                                                        </Storyboard>
                                                    </VisualState>
                                                    <VisualState x:Name="Unselected" />
                                                    <VisualState x:Name="Selected">
                                                        <Storyboard>
                                                            <DoubleAnimation Duration="0:0:0.4"
                                                                             Storyboard.TargetName="grid"
                                                                             Storyboard.TargetProperty="(UIElement.Opacity)"
                                                                             To="1"
                                                                             d:IsOptimized="True" />
                                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textBlock" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                                    <DiscreteObjectKeyFrame.Value>
                                                                        <Visibility>Visible</Visibility>
                                                                    </DiscreteObjectKeyFrame.Value>
                                                                </DiscreteObjectKeyFrame>
                                                            </ObjectAnimationUsingKeyFrames>
                                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="txtCount" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                                    <DiscreteObjectKeyFrame.Value>
                                                                        <Visibility>Visible</Visibility>
                                                                    </DiscreteObjectKeyFrame.Value>
                                                                </DiscreteObjectKeyFrame>
                                                            </ObjectAnimationUsingKeyFrames>
                                                        </Storyboard>
                                                    </VisualState>
                                                </VisualStateGroup>
                                            </VisualStateManager.VisualStateGroups>
                                            <Grid x:Name="grid"
                                                  Background="{StaticResource HighlightBrush}"
                                                  Opacity="0" />

                                            <StackPanel Margin="6">
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="Auto" />
                                                        <ColumnDefinition />
                                                        <ColumnDefinition Width="Auto" />
                                                    </Grid.ColumnDefinitions>
                                                    <TextBlock FontWeight="Bold" Text="{Binding Name}" />

                                                    <TextBlock Name="txtCount"
                                                               Grid.Column="1"
                                                               Foreground="OrangeRed"
                                                               Visibility="Collapsed">
                                                        <Run Text="【共 " />
                                                        <Run Text="{Binding Path=DataContext.DeviceCount, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" />
                                                        <Run Text=" 台设备】" />
                                                    </TextBlock>

                                                    <StackPanel Grid.Column="2" Orientation="Horizontal">
                                                        <Button Margin="12,0"
                                                                Foreground="White"
                                                                Style="{StaticResource EditButtonStyle}">
                                                            <i:Interaction.Triggers>
                                                                <i:EventTrigger EventName="Click">
                                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.UpdateCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                                </i:EventTrigger>
                                                            </i:Interaction.Triggers>
                                                        </Button>
                                                        <Button Foreground="White" Style="{StaticResource DeleteButtonStyle}" />
                                                    </StackPanel>
                                                </Grid>

                                                <TextBlock x:Name="textBlock"
                                                           Foreground="White"
                                                           Text="{Binding Description}"
                                                           TextWrapping="Wrap"
                                                           Visibility="Collapsed" />
                                            </StackPanel>


                                        </Grid>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ListBox.ItemContainerStyle>
                </ListBox>
            </Grid>

            <ToggleButton Grid.Column="1" IsChecked="{Binding ShowDeviceList, Mode=TwoWay}">
                <ToggleButton.Style>
                    <Style TargetType="ToggleButton">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ToggleButton">
                                    <Grid>
                                        <Rectangle Fill="White" Opacity="0" />
                                        <Path Width="16"
                                              Height="16"
                                              Margin="0,0,0,0"
                                              Data="M582.309,226.984L547.355,194.984 582.309,162.984 582.309,226.984z"
                                              Fill="{StaticResource HighlightBrush}"
                                              RenderTransformOrigin="0.5,0.5"
                                              Stretch="Uniform"
                                              Visibility="{Binding IsChecked,
                                                                   RelativeSource={RelativeSource TemplatedParent},
                                                                   Converter={StaticResource BooleanToVisibilityInverseConverter}}">
                                            <Path.RenderTransform>
                                                <TransformGroup>
                                                    <TransformGroup.Children>
                                                        <RotateTransform Angle="0" />
                                                        <ScaleTransform ScaleX="1" ScaleY="1" />
                                                    </TransformGroup.Children>
                                                </TransformGroup>
                                            </Path.RenderTransform>
                                        </Path>
                                        <Path Width="16"
                                              Height="16"
                                              Margin="0,0,0,0"
                                              Data="M299.134,162.984L334.087,194.984 299.134,226.984 299.134,162.984z"
                                              Fill="{StaticResource HighlightBrush}"
                                              RenderTransformOrigin="0.5,0.5"
                                              Stretch="Uniform"
                                              Visibility="{Binding IsChecked,
                                                                   RelativeSource={RelativeSource TemplatedParent},
                                                                   Converter={StaticResource BooleanToVisibilityConverter}}">
                                            <Path.RenderTransform>
                                                <TransformGroup>
                                                    <TransformGroup.Children>
                                                        <RotateTransform Angle="0" />
                                                        <ScaleTransform ScaleX="1" ScaleY="1" />
                                                    </TransformGroup.Children>
                                                </TransformGroup>
                                            </Path.RenderTransform>
                                        </Path>
                                    </Grid>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ToggleButton.Style>
            </ToggleButton>

            <ItemsControl Grid.Column="2"
                          Width="300"
                          ItemsSource="{Binding DeviceCollection}"
                          Visibility="{Binding ShowDeviceList,
                                               Converter={StaticResource BooleanToVisibilityConverter}}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Margin="0,12,0,0"
                                   FontSize="18"
                                   Text="{Binding DeviceSn}" />
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>

        </Grid>

        <controls:PromptDialog Title="{Binding Operation,
                                               Converter={StaticResource EnumTranslationConverter},
                                               ConverterParameter=ENTITYOPERATION}"
                               HorizontalContentAlignment="Stretch"
                               VerticalContentAlignment="Stretch"
                               CloseCommand="{Binding CancelCommand}"
                               Padding="50"
                               Visibility="{Binding ShowUpdate,
                                                    Converter={StaticResource BooleanToVisibilityConverter}}"
                               WindowHeight="240"
                               WindowWidth="400">
            <Grid Margin="12" HorizontalAlignment="Stretch">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <StackPanel>
                    <TextBlock Text="名称" />
                    <TextBox Text="{Binding UpdateEntity.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    <TextBlock Text="描述" />
                    <TextBox AcceptsReturn="True"
                             Text="{Binding UpdateEntity.Description,
                                            Mode=TwoWay,
                                            UpdateSourceTrigger=PropertyChanged}"
                             TextWrapping="Wrap" />
                </StackPanel>

                <StackPanel Grid.Row="1"
                            HorizontalAlignment="Right"
                            Orientation="Horizontal">
                    <Button Width="60"
                            Margin="12,0"
                            Command="{Binding SubmitCommand}"
                            Content="提交" />
                    <Button Width="60"
                            Command="{Binding CancelCommand}"
                            Content="取消" />
                </StackPanel>
            </Grid>
        </controls:PromptDialog>
    </Grid>
</navigation:PageView>
